package com.ssm.modules.service.impl;

import com.ssm.modules.dao.ICourseDao;
import com.ssm.modules.entity.Course;
import com.ssm.modules.service.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @email: dong980514280@gmail.com
 * @author: HGL
 * @date: 2018/12/18
 * @time: 22:25
 */
@Service("courseService")
public class CourseServiceImpl implements ICourseService {

    @Autowired
    private ICourseDao courseDao;

    public List<Course> selectAll() {
        return courseDao.selectAll();
    }

    public int addCourse(Course course) {
        return courseDao.addCourse(course);
    }

    public int updateCourse(Course course){
        return courseDao.updateCourse(course);
    }

    public int deleteCourse(int id){
        return courseDao.deleteCourse(id);
    }

    public List<Course> findByStuId(int stuId, int page, int pageSize) {
        if(page > 0) {
            page = (page - 1) * pageSize;
        }
        return courseDao.findByStuId(stuId, page, pageSize);
    }

    public int findByStuIdCount(int stuId) {
        return courseDao.findByStuIdCount(stuId);
    }

    public List<Course> findByTeaId(int teaId, int page, int pageSize) {
        if(page > 0) {
            page = (page - 1) * pageSize;
        }
        return courseDao.findByTeaId(teaId, page, pageSize);
    }

    public int findByTeaIdCount(int teaId) {
        return courseDao.findByTeaIdCount(teaId);
    }

    public List<Course> findByTeaIdAndCourseId(int teaId, int courseId, int page, int pageSize) {
        if(page > 0) {
            page = (page - 1) * pageSize;
        }
        return courseDao.findByTeaIdAndCourseId(teaId, courseId, page, pageSize);
    }

    public int findByTeaIdAndCourseIdCount(int teaId, int courseId) {
        return courseDao.findByTeaIdAndCourseIdCount(teaId, courseId);
    }

    public int grade(int stuId, int score, int courseId) {
        return courseDao.grade(stuId, score, courseId);
    }
}
